<?php
/**
 * This file contains the class ResetPasswordView which provides
 * all of the text requirements for resetting a password
 *
 * @copyright  2009 A Memory Tree
 * @license    A Memory Tree License
 * @version    $Id:$
 * @link       http://my-trac.assembla.com/amemorytree/ticket/??
 * @since      File available since Release 0.1
 */
/**
 * This class provides the text for ResetPasswordView
 *
 * @copyright  2009 A Memory Tree
 * @license    A Memory Tree License
 * @version    Release: @package_version@
 * @link       http://my-trac.assembla.com/amemorytree/ticket/??
 * @since      Class available since Release 0.1
 */
class ResetPasswordView
{
    /**
     * A place to store pre-prepared messages
     *
     * @var array[string]string
     */
    private $_text;
    /**
      * The html class that provides helpers to display the text
     *
     * @var Html
     */
    private $_html;
    /**
     * Builds the list of text messages
     * 
     * @return void
     * @param Html &$html
     */
    function __construct(&$html)
    {
        $this->_html = $html;
        $this->_text['badPassword'] = '<h2>Password Match Error!</h2>';
        $this->_text['setSuccess'] = '<h2>New Password Successful</h2>';
        $this->_text['setFailure'] = '<h2>The new password failed to be set.</h2>';
    }
    /**
     * Return the text that's associated with the given name
     * 
     * @return string
     * @param string $name
     */
    function text($name)
    {
        return $this->_text[$name];
    }
    /** The form to reset a password
     *
     * @return string
     */
    function resetPasswordPage()
    {
        $file = $_SERVER['PHP_SELF'];
        return <<< EOT
        <h3>Reset Your Password</h3>
        <p>Please enter your username or email address. An email to help you set your password will be sent out to your registered email address.</p>
        <form action="$file" method="post">
            <input type="hidden" name="action" value="reset">
            <table>
                <tr>
                    <td colspan="2" style="padding:5px;">
                        <label style="font-size:11pt;color:red;text-align:right;">Username/Email: </label>
                        <input name="username" />
                    </td>
                </tr>
                <tr>
                    <td align="right" style="padding:5px;">
                        <input type="submit" class="button" value="Reset Account">
                    </td>
                </tr>
            </table>
        </form>

EOT;
    }
    /**
         
         */
    function badUsername()
    {
        return <<< EOT
        <p>Oops,</p>
        <p>You have entered an incorrect username. Please try again.</p>
        <p>If you have trouble remembering your username, simply use your email address and select set account below.</p>
        <p>If your email address is on our system, you will receive an email that states your username, and a link to follow so that you can set your password.</p>
        <p>The link to activate your account will expire after two (2) hours.</p>
        <p>If you do not receive the email within the next few minutes, please check your junk and SPAM mail.</p>
        
EOT;
    }
    /** The message that's shown when the password is successfully reset
     *
     * @return string
     * @param string $email
     */
    function emailSent($email)
    {
        return <<< EOT
            <h2>Check Your Email</h2>
            <p>An automated email has been sent to <strong>$email</strong></p>
            <p><strong>The link in the email will be valid for the next two (2) hours.</strong></p></p>
            <p>If you do not receive the email within the next few minutes please check your junk and SPAM mail.</p>

EOT;
    }
    /** The email message the reset a users account
     *
     * @return string
     * @param int $userId
     * @param string $username
     * @param string $authCode
     */
    function resetEmail($userId, $username, $authCode)
    {
        $html = $this->_html;
        $domain = $_SERVER['SERVER_NAME'];
        $file = $_SERVER['PHP_SELF'];
        $message = <<< EOT
<html>
    <body>
        <p>Hi</p>
        <p>This email has been sent to you as we have received a request to set your account password.</p>
        <p><strong>Your Username is - %s</strong></p>
        <p><strong><a href="http://%s?userid=%d&amp;auth=%s">Set Password</a></strong>
        <p>Clicking on the above link will take you back to the website, authenticate your request, and allow you to set your password.</p>
        <p>If you did not make this request, please ignore this email, or advise us at abuse@amemorytree.co.nz</p>
        <p>Regards</p>
        <p>The Team</p>
        <p><a href="http://www.amemorytree.co.nz/">www.amemorytree.co.nz</a></p>
        <p>create, remember, enjoy, learn, share & discover...</p>
    </body>
</html>
EOT;
        return sprintf($message,
            $html->text($username),
            $html->text($domain.$file),
            $html->text($userId),
            $html->text($authCode)
        );
    }
    /**
     * The authentication success message
     *
     * @return string
     * @param string $authCode
     */
    function authenticationSuccess()
    {
        return <<< EOT
                <h2 style="padding:2px;">Authentication was Successful</h2>
                <p>We have verified your email address and you can now set your password.</p>

EOT;
    }
    /**
     * The authentication failed message
     *
     * @return string
     */
    function authenticationFailure()
    {
        return <<< EOT
                <h2 style="padding:2px;">Account Authentication</h2>
                <p>Email authentication failed.</p>

EOT;
    }
    /** The form to login with
     *
     * @return string
     * @param string $username
     * @param string $authCode
     */
    function loginForm($username, $authCode, $returnPage)
    {
        $html = $this->_html;
        $file = $_SERVER['PHP_SELF'];
        return <<< EOT
            <form action="$file" method="post">
                <table cellpadding="2" cellspacing="2">
                    <tr>
                        <input type="hidden" name="action" value="setPassword">
                        <input type="hidden" name="auth" value="$authCode">
                        <input type="hidden" name="return" value="$returnPage">
                        <td><label style="font-size:11pt;color:red;">Username: </label></td>
                        <td style="padding:5px;"><input name="username" value="$username" /></td>
                    </tr>
                    <tr>
                        <td><label style="font-size:11pt;color:red;">Set Password: </label></td>
                        <td style="padding:5px;" align="right"><input type="password" name="resetPassword" /></td>
                    </tr>
                    <tr>
                        <td><label style="font-size:11pt;color:red;">Confirm Password: </label></td>
                        <td style="padding:5px;" align="right"><input type="password" name="confirmPassword" /></td>
                    </tr>
                    <tr>
                        <td colspan="2" align="right" style="padding:5px;"><input type="submit" class="button" value="Set Password"></td>
                    </tr>
                </table>
            </form>

EOT;
    }
    /**
     * The message for when have finished setting the password
     *
     * @return string
     * @param string $name
     * @param string $page
     */
    function redirect($name, $page)
    {
        header('Refresh: 5;url='.$page);
        return <<< EOT
        <p>You will be taken to the $name page in 5 seconds time.</p>
        <p>If the page doesn't load, please go to the <a href="$page">$name</a> page.</p>

EOT;
    }
    /**
     * Show the page contents
     *
     * @return string
     * @param string $text
     */
    function render($text)
    {
        echo <<< EOT
    <div id="centerbar">
        <center>
            $text
        </center>
    </div>

EOT;
    }
}
?>